##########################################
## Copyright 2012-2013 Ceruti Francesco & contributors
##
## This file is part of LiSP (Linux Show Player).
##########################################

from lisp.utils import configuration as cfg

PLUGINS_LIST = cfg.config['Plugins']['Packages'].split(',')

for mod in PLUGINS_LIST:
    if(mod.strip() != ''):
        exec('from . import ' + mod)


def initPlugins(main, debug=True):
    plugins = []
    err = ''
    for plug in PLUGINS_LIST:
        if(plug.strip() != ''):
            if(debug):
                plugins.append(eval(plug + '.build(main)'))
            else:
                try:
                    plugins.append(eval(plug + '.build(main)'))
                except:
                    err += plug + '\n'

    if(err != ''):
        raise Exception('Plugins init failed:\n\n' + err[:-1])

    return plugins
